package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.componentBookPojo;
import com.example.service.componentBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * ClassName:componentBookController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/12 17:07
 * @Version 1.0
 */
@RestController
public class componentBookController {
    @Autowired
    private componentBookService componentBookService;
    //根据baseId，查询某一行的内容
    @PostMapping("/inquiryByFieldAndBaseId")
    public Result inquiryByFieldAndBaseId(@RequestBody Map<String, Object> parameters){
        componentBookPojo fieldVar=componentBookService.inquiryByFieldAndBaseId(parameters);
        return Result.success(fieldVar);
    }
    //修改数据，发id，修改的字段名，修改的字段值,根据ID，修改某一个字段的值。
    @PostMapping("/editComponentBookByIDByField")
    public Result editComponentBookByIDByField(@RequestBody Map<String, Object> parameters){
        String felidVal=componentBookService.editComponentBookByIDByField(parameters);
        return Result.success(felidVal);
    }
    //上传图片的函数
    @PostMapping("/componentPicture")
    public Result componentPicture(@RequestParam("file") MultipartFile file, @RequestParam Integer id, @RequestParam String fieldName,@RequestParam String fieldVal){
        String allName = componentBookService.componentPicture(file,id,fieldName,fieldVal);
        return Result.success(allName);
    }
    //删除图片的函数
    @PostMapping("/componentPictureRemove")
    public Result componentPictureRemove(@RequestBody Map<String, Object> parameters){
        String fileName=componentBookService.componentPictureRemove(parameters);
        return Result.success(fileName);
    }
}
